1
00:00:00,450 --> 00:00:10,530
Hello there welcome to this video on conditional statement conditional statements are code that will

2
00:00:10,620 --> 00:00:23,100
allow us to test whether an expression or condition is true and then run or executed could depending

3
00:00:23,130 --> 00:00:29,230
on that condition saw form condition It's true Iran has one could.

4
00:00:29,450 --> 00:00:30,890
It's not Iran.

5
00:00:30,910 --> 00:00:38,830
The other code and the most common type of conditional statements in Gap a script is core.

6
00:00:39,090 --> 00:00:46,060
IF ELSE state so this is an example of an IF statement code.

7
00:00:46,230 --> 00:00:48,880
So I'll just explain this code for you.

8
00:00:48,880 --> 00:00:58,120
So it begins with a variable and the variable name is car type B value for that variable is Range Rover.

9
00:00:58,500 --> 00:01:01,500
So this is the piece of code you need to fork solidly.

10
00:01:01,500 --> 00:01:06,070
If else and this is how you will write it you begin with it.

11
00:01:06,090 --> 00:01:08,930
If with the word if and then you have peronne.

12
00:01:08,930 --> 00:01:15,990
This is where you put in the condition so this is where you would specify the condition in between the

13
00:01:16,020 --> 00:01:26,350
parentheses So the condition is if the card type which has been declared here is equals to in Javascript

14
00:01:26,360 --> 00:01:32,960
double because to a means equals a single one means we all set in ungiving of giving a value.

15
00:01:33,070 --> 00:01:38,990
So if card type equals to render a vat alert.

16
00:01:39,110 --> 00:01:43,530
This was the code that will be executed will be this.

17
00:01:43,680 --> 00:01:45,890
So a pop up window will come obscene.

18
00:01:45,900 --> 00:01:48,260
I lost my range rover.

19
00:01:48,930 --> 00:01:57,180
If for example the name here is wrong and this is changed to E or something then it will not match the

20
00:01:57,180 --> 00:02:00,590
value here and there when the piece of code runs.

21
00:02:00,660 --> 00:02:05,610
It will now execute this second part because the first part is wrong.

22
00:02:05,820 --> 00:02:08,040
It will not execute alert.

23
00:02:08,100 --> 00:02:11,570
I would like a render of that please.

24
00:02:11,930 --> 00:02:15,430
Ah I have got the code here inside my text.

25
00:02:15,450 --> 00:02:16,970
Add it up.

26
00:02:17,010 --> 00:02:19,280
This is the code here.

27
00:02:19,370 --> 00:02:20,130
All right.

28
00:02:20,130 --> 00:02:22,410
So why is saying here.

29
00:02:22,650 --> 00:02:29,590
If the card type declared here equals to wrong do I want you to alert this message.

30
00:02:29,640 --> 00:02:35,730
I love my renderer if not display the second part of the code.

31
00:02:35,840 --> 00:02:39,140
So this is what is busy if else.

32
00:02:39,240 --> 00:02:41,350
Conditional statement does.

33
00:02:41,430 --> 00:02:43,290
So let me run this code.

34
00:02:43,640 --> 00:02:47,980
Hard yes it is.

35
00:02:48,000 --> 00:02:51,450
I love my brain for a few minutes.

36
00:02:51,570 --> 00:02:58,360
Because the first part of the code if statement is correct there is no need to run the second part.

37
00:02:58,410 --> 00:03:01,640
First condition has been satisfied.

38
00:03:01,800 --> 00:03:05,890
So the condition that place between the between the perowne.

39
00:03:05,920 --> 00:03:08,720
This is very important.

40
00:03:08,720 --> 00:03:15,750
And also dont forget the curly braces where you write in the code curly braces is very important.

41
00:03:15,750 --> 00:03:22,400
So if you notice the curly braces they are highlighted Thus the first one after the if statement so

42
00:03:22,410 --> 00:03:23,620
you go a B.

43
00:03:23,670 --> 00:03:24,970
They always come in pairs.

44
00:03:24,990 --> 00:03:26,150
Curly braces.

45
00:03:26,300 --> 00:03:32,610
So this is the second braith this is a match is for the else statement.

46
00:03:32,670 --> 00:03:37,620
So if the first part of the code is not met it will execute the second part.

47
00:03:37,650 --> 00:03:46,750
For example if I changed the name half I change the name here say airport.

48
00:03:47,640 --> 00:03:50,930
Just change your name pull rate from one end to a save.

49
00:03:50,940 --> 00:03:58,110
If I run that he should give me this second part because that name is wrong.

50
00:03:59,310 --> 00:04:01,670
See that has given me the second part of the code.

51
00:04:01,680 --> 00:04:14,160
I would like a Range Rover please because this image if part of it Icard time is not equal to a Range

52
00:04:14,250 --> 00:04:20,620
Rover because I have purposely spelt it wrong because it doesn't match the value here.

53
00:04:20,640 --> 00:04:25,890
This equals sign is what determines is see value in this card type.

54
00:04:25,900 --> 00:04:28,760
This variable must match this

55
00:04:31,900 --> 00:04:35,760
right so this is how you would write an IF ELSE statement.

56
00:04:35,820 --> 00:04:38,680
Always remember the curly braces after that.

57
00:04:38,790 --> 00:04:48,400
If you need to place a curly braces on the condition is place between B parentheses.

58
00:04:48,690 --> 00:04:53,170
Okay so on one condition that does it does condition is not met.

59
00:04:53,280 --> 00:04:58,060
It will execute this condition which is meant to execute this piece of code here.

60
00:04:58,290 --> 00:04:59,850
If it is not met it will.

61
00:05:00,180 --> 00:05:02,600
Excuse this piece of code.

62
00:05:02,710 --> 00:05:03,020
Some.

63
00:05:03,020 --> 00:05:08,330
Got another one here written for icecream by the same the same format.

64
00:05:08,330 --> 00:05:13,070
So this is just another piece of code with an if else statement.

65
00:05:13,070 --> 00:05:16,260
So a variable like declare the icecream.

66
00:05:16,330 --> 00:05:25,420
Give me a value off chocolate and this is each state means seeing that if the icecream variable is equal

67
00:05:25,440 --> 00:05:29,630
if you notice he has got three quarters of a D is strictly equal to.

68
00:05:29,870 --> 00:05:37,720
If the icecream is a double That means it was 3 it was two families strictly equals two.

69
00:05:37,970 --> 00:05:43,380
If ice cream is truly equal to chocolate alert Hooray.

70
00:05:43,380 --> 00:05:48,600
I love chocolate so if this is true condition is true it will run its course.

71
00:05:48,730 --> 00:05:51,440
If it is not true it will run the second code.

72
00:05:51,470 --> 00:05:53,080
So let me run.

73
00:05:53,070 --> 00:05:56,950
That's where it should run but could.

74
00:06:00,230 --> 00:06:03,040
Key something awesome to run with the call.

75
00:06:03,050 --> 00:06:05,750
Let's have a look.

76
00:06:06,640 --> 00:06:07,080
All right.

77
00:06:07,100 --> 00:06:10,240
I figured out what was wrong with a cold.

78
00:06:10,370 --> 00:06:10,910
Well done.

79
00:06:10,920 --> 00:06:14,120
I've commented that this part of it but that wasn't the problem.

80
00:06:14,120 --> 00:06:20,030
The problem was I left out this curly braces here here it's very important that your curly braces to

81
00:06:20,030 --> 00:06:23,070
match if not the cold will not run.

82
00:06:23,090 --> 00:06:24,590
So I missed this one.

83
00:06:24,590 --> 00:06:25,830
That's why I didn't run.

84
00:06:26,060 --> 00:06:32,810
So I see they have to be paired that one Piers with that and they pay that if he's not pay it will not

85
00:06:32,810 --> 00:06:33,440
run.

86
00:06:33,470 --> 00:06:41,990
So let me run this quote and you can see when it starts says hooray I love chocolate ice cream because

87
00:06:42,060 --> 00:06:50,810
the first condition here has been met saying if this condition is met a lot just messy if not alert

88
00:06:50,870 --> 00:06:52,700
the sick on code.

89
00:06:52,730 --> 00:07:00,620
So because this was conditional statements do enjoy have a scrip they used to test if a condition is

90
00:07:00,620 --> 00:07:08,100
true or not and based on that the court specified or wrong so it doesn't run all the time because with

91
00:07:08,150 --> 00:07:09,050
all Iran.

92
00:07:09,170 --> 00:07:13,960
If the condition is met or right in is your.

93
00:07:13,970 --> 00:07:18,170
I explained what conditional States means to be.

94
00:07:18,170 --> 00:07:25,420
I used to run quantised cool based on certain conditions.

95
00:07:25,730 --> 00:07:34,730
So if one condition is true it will execute one block of code and if the so forth condition is true

96
00:07:34,760 --> 00:07:37,950
it executes the first block of call.

97
00:07:38,180 --> 00:07:39,370
If is not true.

98
00:07:39,530 --> 00:07:41,960
Execute the second block of code.

99
00:07:42,150 --> 00:07:46,480
So this is how conditional statements work in JAMA scrip.

100
00:07:46,610 --> 00:07:48,330
Thank you so much for watching.

101
00:07:48,440 --> 00:07:51,030
I hope the EU has been useful.

102
00:07:51,260 --> 00:07:52,190
Thank you.

103
00:07:52,210 --> 00:07:52,940
Bye for now.